package com.rs.game.npc.combat.impl;

import com.rs.game.Animation;
import com.rs.game.Entity;
import com.rs.game.ForceTalk;
import com.rs.game.Graphics;
import com.rs.game.Hit;
import com.rs.game.Hit.HitLook;
import com.rs.game.npc.NPC;
import com.rs.game.npc.combat.CombatScript;
import com.rs.game.npc.combat.NPCCombatDefinitions;
import com.rs.utils.Utils;
import com.rs.game.player.Player;

public class ThunderCombat extends CombatScript {

	//private Object familiar;

	@Override
	public Object[] getKeys() {
		return new Object[] { 11872 };
	}

	@Override
	public int attack(final NPC npc, final Entity target) {
		final NPCCombatDefinitions defs = npc.getCombatDefinitions();
		if (Utils.getRandom(4) == 0) {
			switch (Utils.getRandom(3)) {
			case 0:
			npc.setNextForceTalk(new ForceTalk("RAAAAAARRRRRRGGGGHHHH"));
			break;
		case 1:
			String name = "";
			if (target instanceof Player)
				name = ((Player) target).getDisplayName();
			npc.setNextForceTalk(new ForceTalk("You're going straight to hell, " +name));
			break;
		case 2:
			name = "";
			if (target instanceof Player)
				name = ((Player) target).getDisplayName();
			npc.setNextForceTalk(new ForceTalk("I'm going to crush you, " + name));
			break;
		case 3:
			name = "";
			if (target instanceof Player)
				name = ((Player) target).getDisplayName();
			npc.setNextForceTalk(new ForceTalk("You will heal me, " + name));
			npc.setNextAnimation(new Animation(14525));
			npc.setNextGraphics(new Graphics(2798));
			npc.heal(500);
			npc.applyHit(new Hit(npc, 500, HitLook.HEALED_DAMAGE));
			break;
		}
		}
		if (Utils.getRandom(1) == 0) { // mage magical attack
			npc.setCapDamage(800);
			npc.setNextAnimation(new Animation(14525));
			npc.setNextForceTalk(new ForceTalk("FEEL THE POWER!"));
			for (Entity t : npc.getPossibleTargets()) {
				if (!t.withinDistance(npc, 18))
					continue;
				int damage = getRandomMaxHit(npc, defs.getMaxHit(),NPCCombatDefinitions.MAGE, t);
				if (damage > 0) {
					delayHit(npc, 1, t, getMagicHit(npc, damage));
					t.setNextGraphics(new Graphics(3428));
					if (t instanceof Player) {Player p = (Player) t;p.getPrayer().drainPrayerOnHalf();
				}
			}
		}
		} else { // melee attack
			npc.setNextAnimation(new Animation(defs.getAttackEmote()));
			npc.setCapDamage(800);
			delayHit(npc,0,target,getMeleeHit(npc,getRandomMaxHit(npc, defs.getMaxHit(),
					NPCCombatDefinitions.MELEE, target)));
			}
		return defs.getAttackDelay();
	}
}